java与c#的socket通信问题!求解答呀
本人做了个Java与C#进行Socket通信程序,使用java做了个客户端,C#做了个服务器端,两个程序进行Socket连接成功,客户端发送的数据服务器端可以收到,但服务器端返回数据时,客户端却收不到哦 ? 这是怎么回事啊 ?请高手指点
java:
import java.io.*;
import java.net.*;
public class myclass {
public static void main(String[] args)throws
IOException
{
System.out.println("ready to test!\n");
run("127.0.0.1",33333);
}
public static void run(String hostip,int hostport)
{
try
{
Socket server = null;
String str = "this is amazing!";//null;
server = new Socket(hostip,hostport);
System.out.println("Connecting server\n");
/* OutputStream outstrm = server.getOutputStream();
DataOutputStream dos = new DataOutputStream(outstrm);
dos.writeUTF(str);
dos.flush();
dos.close();
*/
InputStream instrm = server.getInputStream();
DataInputStream dis =new DataInputStream(instrm);
System.out.println("utf !!!\n");
System.out.println(dis.readUTF());
dis.close();
server.close();
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
}
c#:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections;
namespace GPSServer
{
class Program
{
private static Thread mythread;
// private static IPAddress serverIP = IPAddress.Parse("192.168.200.130");
private static IPEndPoint ipep;
private static Socket server;
static void Main(string[] args)
{
mythread = new Thread(new ThreadStart(BeginListen));
Console.WriteLine("监听");
mythread.Start();
Console.WriteLine("线程启动");
}
private static void BeginListen()
{
int recv;
ipep = new IPEndPoint(IPAddress.Any, 33333);
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);