asp.NET能做socket,线程,画图并生成gif图片吗?

213yy 2003-11-09 09:47:29
hi,各位,我没摸过asp.NET
asp.NET能做socket,线程,画图并生成gif图片吗?
采用c#写代码,然后在aspx中调用应该是没问题的吧?
就好比在jsp中调用javabean一样吗?
如果可以的话,能给一个思路吗?

有画股票走势图的代码吗?
此贴分不够,可以再开一贴给分.
...全文
31 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
gOODiDEA 2003-11-14
  • 打赏
  • 举报
回复
Introduction to Socket Programming and HTTP

http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=396&printer=t
ddangerous169 2003-11-14
  • 打赏
  • 举报
回复
now,usually i use C# to create a class to build bitmap
but not use socks
速马 2003-11-14
  • 打赏
  • 举报
回复
如果只是打算同步的获得数据,可以使用TcpClient,TcpListener,和UdpClient.
使用上简单的多.下面是TcpClient的例子(MSDN里copy来的)

The following example establishes a TcpClient connection.
[Visual Basic]
Shared Sub Connect(server As [String], message As [String])
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
Dim port As Int32 = 13000
Dim client As New TcpClient(server, port)

' Translate the passed message into ASCII and store it as a Byte array.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()

' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)

Console.WriteLine("Sent: {0}", message)

' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](256) {}

' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty

' Read the first batch of the TcpServer response bytes.
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}", responseData)

' Close everything.
client.Close()
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}", e)
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try

Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
Console.Read()
End Sub 'Connect
[C#]
static void Connect(String server, String message)
{
try
{
// Create a TcpClient.
// Note, for this client to work you need to have a TcpServer
// connected to the same address as specified by the server, port
// combination.
Int32 port = 13000;
TcpClient client = new TcpClient(server, port);

// Translate the passed message into ASCII and store it as a Byte array.
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);

// Get a client stream for reading and writing.
// Stream stream = client.GetStream();

NetworkStream stream = client.GetStream();

// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);

Console.WriteLine("Sent: {0}", message);

// Receive the TcpServer.response.

// Buffer to store the response bytes.
data = new Byte[256];

// String to store the response ASCII representation.
String responseData = String.Empty;

// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
Console.WriteLine("Received: {0}", responseData);

// Close everything.
client.Close();
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}

Console.WriteLine("\n Press Enter to continue...");
Console.Read();
}
速马 2003-11-14
  • 打赏
  • 举报
回复
// 页面请求的时候,c#代码就通过socket实时的向服务器请求数据,并将数据提交给aspx页面

如果我没有理解错的话,你需要的只是从服务器得到数据,再用这些数据生成图片?
如果只是这样何必非得使用socket呢?用数据库或者文件不都可以吗

如果要使用socket,可以参考MSDN里面的.NET Reference
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetSockets.asp?frame=true
速马 2003-11-14
  • 打赏
  • 举报
回复
// 想aspx页面请求的时候, c#代码就通过socket实时取数据

那么看起来你要求的不是实时刷新的那种页面
就是请求一个aspx页面, 这个页面显示出你要的数据, 而这些数据通过socket获得?

那么关于socket的代码可以写在aspx.cs里面的private void Page_Load里面啊

或者, 我觉得你这样的程序最好先做个Windows服务缓冲, 这个service在后台运行, 不断的从"数据服务器"获得数据并更新到本地数据库(可以是数据库也可以是XML等等), 页面请求就可以直接访问本地数据, 效率上高一点
213yy 2003-11-14
  • 打赏
  • 举报
回复
to Sunmast(速马):
你说的很有道理,但是这和业务有着很大的关系,
因为服务器是一个实时的数据处理机,我需要与它通讯获取
数据,并在aspx页面请求数据的时候,将数据&&用数据生成的图片
递交。这样的话,我是不是要做一个类似于java中的Bean一样的东西?
结构如下:

aspx <----> c#(类似Bean的c#模块) <---->数据服务器

c#(类似Bean的c#模块) 这个东西,一边要和数据服务器打交道,一边要和页面打交道.
这个东西 ....应该是要做成个什么样子的比较好? 应用程序?控制台程序?纯c#类?

没搞过asp.NET,特写了一大片,请教了。
zsww 2003-11-14
  • 打赏
  • 举报
回复
学习!!!

-----------努力学习 不断实践 虚心讨教---------
213yy 2003-11-13
  • 打赏
  • 举报
回复
d
acewang 2003-11-10
  • 打赏
  • 举报
回复
实时刷新的?
213yy 2003-11-10
  • 打赏
  • 举报
回复
d
213yy 2003-11-10
  • 打赏
  • 举报
回复
我想做的程序就是Sunmast(速马)你说的 .具体的就是实时请求数据并生成图片,
提交给aspx页面显示.

aspx页面请求的时候,c#代码就通过socket实时的向服务器请求数据,并将数据提交给aspx
页面并显示。

谁能给我一个这样的demo么?
lishao 2003-11-10
  • 打赏
  • 举报
回复
楼上这么多高手呀,借用宝地,问一个简单的socket问题,我用socket发了数据后,马上接收,解析数据,发现有时不对,最后找到原因,有的时候socket发了数据包后,不能马上接收,好像是socket的什么选项,怎么做的?能否给断代吗?
速马 2003-11-10
  • 打赏
  • 举报
回复
你要的全部都可以而且很简单

// 想aspx页面请求的时候,c#代码就通过socket实时取数据

想做什么样的程序? 具体的?
213yy 2003-11-10
  • 打赏
  • 举报
回复
不要要实时刷新的,只是想aspx页面请求的时候,c#代码就通过socket实时取数据.
gOODiDEA 2003-11-10
  • 打赏
  • 举报
回复
生成图:

public Bitmap CreateImage( string Text, Font font, Color ForeColor, Color BackgroundColor )
{
Bitmap bm = new Bitmap( 100, 100 );
Graphics gs = Graphics.FromImage( bm );
bm = new Bitmap( Convert.ToInt32( gs.MeasureString( Text, font ).Width ), Convert.ToInt32( gs.MeasureString( Text, font ).Height ) );
gs = Graphics.FromImage( bm );
gs.Clear( BackgroundColor );
gs.TextRenderingHint = TextRenderingHint.AntiAlias;
gs.DrawString( Text, font, new SolidBrush( ForeColor ), 0, 0 );
gs.Flush();
return bm;
}
realsnow 2003-11-10
  • 打赏
  • 举报
回复
这么多高手都来了阿

学习
elite2018 2003-11-09
  • 打赏
  • 举报
回复
of course It can do it ,

u can use assembly , it can be called just like javabean

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧